package wendyeq.iweb.blog.web.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import wendyeq.iweb.blog.pojo.Comment;
import wendyeq.iweb.blog.service.ICommentService;

@Controller
@RequestMapping("/admin/comment")
public class CommentController {
	
	@Resource(name="commentServiceImpl")
	private ICommentService commentService;
	
	@RequestMapping("")
	public String comment(HttpServletRequest request, ModelMap model) {
		return "admin/comment";
	}
	
	@RequestMapping("del/{id}")
	public String delComment(@PathVariable String id, HttpServletRequest request, ModelMap model) {
		this.commentService.delete(id);
		model.addAttribute("comments", this.commentService.findAll());
		return "admin/comment";
	}
	
	@RequestMapping("list/{page}")
	public String listComment(@PathVariable int page, HttpServletRequest request, ModelMap model) {
		List<Comment> comments = this.commentService.findByPage((page-1)*15,page*15);
		int comSize = comments.size();
		model.addAttribute("comments",comments);
		model.addAttribute("catSize", comSize);
		model.addAttribute("page", page);
		return "admin/commentList";
	}
}
